package org.jod.anarchytrek.ship;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.jod.anarchytrek.AComponent;
import org.jod.anarchytrek.ITimerableComponent;
import org.jod.anarchytrek.component.Eps;
import org.jod.anarchytrek.component.Nacelle;
import org.jod.anarchytrek.component.WarpDrive;
import org.jod.anarchytrek.componentfactory.EpsFactory;
import org.jod.anarchytrek.componentfactory.NacelleFactory;
import org.jod.anarchytrek.componentfactory.WarpDriveFactory;
import org.jod.anarchytrek.util.StructuralUnitsUtil;

public class Ship extends ASchip implements ITimerableComponent {

    private String _userName;
    private Map _components;
    private Map _infoComponents;

    public Ship(String aUserName, int aShipClass) {
        super(aShipClass);
        _userName = aUserName;
        _components = new HashMap();
        _infoComponents = new HashMap();

        buildEpsGrid();
    }

    public String name() {
        return _userName;
    }

    
    public void timed() {
        ((ITimerableComponent) _components.get(AComponent.EPS)).timed();
        ((ITimerableComponent) _components.get(AComponent.WARPDRIVE)).timed();
    }

    public void register() {
        ((Eps)_components.get(AComponent.EPS)).register( (WarpDrive) _components.get(AComponent.WARPDRIVE) );
        ((Eps)_components.get(AComponent.EPS)).register( (Nacelle) _components.get(AComponent.NACELLE) );
    }
    
    private void buildEpsGrid() {
        new EpsFactory(_infoComponents, _components, structuralUnits()).build();
    }

    public void addWarpDrive(String aWarpDriveType) {
         addComponent(AComponent.WARPDRIVE, new WarpDriveFactory(_infoComponents, _components, aWarpDriveType));
    }

    public void addNacelle(String aNacelleType) {
        addComponent(AComponent.NACELLE, new NacelleFactory(_infoComponents, _components, aNacelleType));
    }
    

}
